package unit4.part12.ticTacToe;

public class Player {
    private final String name;
    private final int[][] positions;
    private int num = 0;

    public Player(String name, int n) {
        this.name = name;
        positions = new int[n][n];
    }

    public void addPosition(int i, int j) {
        positions[i][j] = 1;
        num++;
    }

    public boolean isSuccess() {
        int slashSum1 = 0, slashSum2 = 0;
        for (int i = 0; i < positions.length; i++) {
            int rowSum = 0;
            int colSum = 0;
            for (int j = 0; j < positions[i].length; j++) {
                rowSum += positions[i][j];
                colSum += positions[j][i];
            }
            if (rowSum >= positions.length || colSum >= positions.length) {
                return true;
            }
            slashSum1 += positions[i][i];
            slashSum2 += positions[i][positions.length - i - 1];
        }
        return slashSum1 >= positions.length || slashSum2 >= positions.length;
    }

    public String getName() {
        return name;
    }

    public int getNum() {
        return num;
    }
}
